package cn.b.sky.form.form.builder.impl;

import cn.b.sky.form.form.builder.BaseElementBuilder;
import cn.b.sky.form.model.BusinessField;
import cn.b.sky.form.model.ScreenField;
import org.apache.commons.lang3.StringUtils;

public class CheckBoxBuilder extends BaseElementBuilder {

  @Override
  public String buildHtmlElement(ScreenField sf) {
    BusinessField field = sf.getBf();
    StringBuilder sb = new StringBuilder();
    sb.append("<input type=\"checkbox\"");
    if (sf.getReadonlyFlag() == 1) {
      sb.append(" disabled=\"disabled\"");
    }
    if (!StringUtils.isBlank(field.getDbField()) && sf.getReadonlyFlag() != 1) {
      sb.append(" id=\"").append(field.getDbField()).append("\"");
      sb.append("name=\"").append(field.getDbField()).append("\"");;
    }
    //输入框检验
    String validation = this.getValidationAttribute(field);
    if (!StringUtils.isBlank(validation)) {
      sb.append(" class=\"").append(validation).append("\"");
    }
    sb.append(" value=\"1\"");
    if("1".equals(field.getDefaultValue())){
      sb.append(" checked=\"checked\"");
    }
    sb.append(" />");
    return sb.toString();
  }

}
